package me.w70.fps.render;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

public class ImageData {
	private BufferedImage bimg;
	public int width;
	public int height;
	public int[][] data;
	
	public ImageData() {
		
	}
	
	public void feedHardcodedData(int w, int h, int[][] newdata) {
		this.width = w;
		this.height = h;
		this.data = new int[w][h];
		for (int x = 0; x < w; x++) {
			for (int y = 0; y < w; y++) {
				this.data[x][y] = newdata[x][y];
			}
		}
	}
	
	public void printdata() {
		System.out.println("public static int BLUESTONECELLSKELETON_WIDTH = " + this.width + ";");
		System.out.println("public static int BLUESTONECELLSKELETON_HEIGHT = " + this.height + ";");
		System.out.print("public static int[][] BLUESTONECELLSKELETON_DATA = { ");
		for (int[] x : data) {
			System.out.print("{ ");
			for (int y : x) {
				System.out.print(y + ",");
			}
			System.out.print(" },\n");
		}
		System.out.print("};");
	}
	
	public void convertfromimage(BufferedImage theimage) {
		this.bimg = theimage;
		this.width = theimage.getWidth();
		this.height = theimage.getHeight();
		this.data = new int[width][height];
		for (int x = 0; x < this.width; x++) {
			for (int y = 0; y < this.height; y++) {
				int pixel = bimg.getRGB(x, y);
				data[x][y] = pixel;
			}
		}
	}
	
	public int getpixel(int x, int y) {
		return this.data[(x % this.width)][y % this.height];
	}
	
	public int getpixel2(int x, int y) {
		return this.bimg.getRGB(x, y);
	}
	
	public void testdraw(Graphics g) {
		for (int x = 0; x < this.width; x++) {
			for (int y = 0; y < this.height; y++) {
				//int[] pix = this.data[(x % this.width) + ((y * this.width) % this.height)];
				//g.setColor(new Color(pix[0], pix[1], pix[2]));
				g.setColor(new Color(this.data[x][y]));
				g.fillRect(x, y, 1, 1);
			}
		}
	}
	
}
